<template>
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap">
		<div class="bt">编辑</div>
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<el-form label-width="100px" class="form">

			<el-form-item label="分类名称">
				<el-select v-model="form.wpflid" disabled class="select-block">
					<el-option :label="v.mc" :value="v.id + ''" v-for="v in comboxlist"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="物品名称">
				<el-input v-model="form.mc"  placeholder="请输入" class="select-block"></el-input>
			</el-form-item>

			<el-form-item label="出售单价" v-if='pand'>
				<el-input v-model="form.jg" v-if='pand' placeholder="请输入" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="单位名称">
				<el-select v-model="form.dw" class="select-block" placeholder="请选择单位">
					<el-option :label="v.mc" :value="v.mc" v-for="v in dwcomboxlist"></el-option>
				</el-select>
			</el-form-item>
			<!--<el-form-item label="是否上架">
				<el-tooltip placement="top" class="sx">
					<el-switch v-model="form.sfsj" active-color="#13ce66" inactive-color="#ff4949" inactive-text="否" active-text="是" active-value="Y" inactive-value="N"></el-switch>
				</el-tooltip>
			</el-form-item>-->
			<!--<el-form-item label="是否配件">
				<el-tooltip placement="top" class="sx">
					<el-switch v-model="form.ispj" active-color="#13ce66" inactive-color="#ff4949" inactive-text="否" active-text="是" active-value="Y" inactive-value="N"></el-switch>
				</el-tooltip>
			</el-form-item>-->
			<el-form-item label="库存预警值">
				<el-input v-model="form.kcxx" placeholder="请输入物品名称" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="物品描述">
				<el-input v-model="form.ms" type="textarea" :rows="2" placeholder="请输入" class="select-block"></el-input>
			</el-form-item>

		</el-form>
		<el-button type="primary" class="submit" @click="submit">修改</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				form: {
					mc: '',
					ms: '',
					jg: '',
					dw: '',
					sfsj: '',
					ispj: '',
					wpfl:'',
					wpurl: '',
					wpflid: '',
					id: ''
				},
				pand:false,
				comboxlist: [],
				dwcomboxlist: [],
			}
		},
		created() { 
			console.log(this.params,'llll')
			this.form.id = this.params.row.id;
			this.form.wpfl = this.params.row.wpfl;
			this.getcomboxlist();
			this.getdwcomboxlist();
			this.loadinfo();
		},
		methods: {
			loadinfo() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id,
					id: this.form.id,
					wpfl:this.form.wpfl
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfx/info', params2)
					.then(res => { 
						this.form = res.data.data
						if(res.data.data.sz=='Y'){
							this.pand=true;
						}
					}).catch(res => {
						this.$message.danger("服务器异常");
						this.$emit('close', {type: 'info',cancel: true});
					})
			},
			getdwcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'bq/hddw', params2)
					.then(res => { 
						let data = res.data.data;
						let list = data.list;
						this.dwcomboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			submit() {
				//检测
				this.$store.state.loading = true;
				//装载数据
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					id: this.form.id,
					mc: this.form.mc,
					ms: this.form.ms,
					jg: this.form.jg,
					dw: this.form.dw,
//					ispj: this.form.ispj,
					sfsj: this.form.sfsj,
					kcxx: this.form.kcxx,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					wpflid: this.form.wpflid
				});
				//执行
				this.axios.post(this.$store.state.api + 'wpfx/update', params2)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {type: 'edit',cancel: false});
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器异常");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', {type: 'edit',cancel: true})
			},
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					keywork: this.jcmc,
					pageindex: 1,
					pagesize: 1000
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfl/list', params2)
					.then(res => { 
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list; 
					}).catch(res => {
						this.searchLoading = false;
					})
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	
	.bt {
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		margin-bottom: 20px;
		color: white;
		text-align: left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
	
	.form {
		text-align: left;
		margin-top: 20px;
	}
	
	.input {
		display: inline-block;
	}
	
	.select-block {
		display: block;
		width: 85%;
	}
	
	.submit {
		width: 120px;
	}
</style>